package org.kabeja.parser.table;

import org.kabeja.dxf.DXFConstants;
import org.kabeja.dxf.entity.DXFStyle;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 14:16
 */
public class DXFStyleTableHandler extends AbstractTableHandler {
    public static final int GROUPCODE_NAME = 2;
    public static final int GROUPCODE_TEXT_HEIGHT = 40;
    public static final int GROUPCODE_WIDTH_FACTOR = 41;
    public static final int GROUPCODE_OBLIQUE_ANGLE = 50;
    public static final int GROUPCODE_TEXT_GENERATION_FLAG = 71;
    public static final int GROUPCODE_FLAGS = 70;
    public static final int GROUPCODE_LAST_HEIGHT = 42;
    public static final int GROUPCODE_FONT_FILE = 3;
    public static final int GROUPCODE_BIG_FONT_FILE = 4;
    private DXFStyle style;

    public DXFStyleTableHandler() {
    }

    @Override
    public void endParsing() {
        this.doc.addDXStyle(this.style);
    }

    @Override
    public String getTableKey() {
        return DXFConstants.TABLE_KEY_STYLE;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case GROUPCODE_NAME:
                this.style.setName(var2.getValue());
                break;
            case GROUPCODE_FONT_FILE:
                this.style.setFontFile(var2.getValue());
                break;
            case GROUPCODE_BIG_FONT_FILE:
                this.style.setBigFontFile(var2.getValue());
                break;
            case GROUPCODE_TEXT_HEIGHT:
                this.style.setTextHeight(var2.getDoubleValue());
                break;
            case GROUPCODE_WIDTH_FACTOR:
                this.style.setWidthFactor(var2.getDoubleValue());
                break;
            case GROUPCODE_LAST_HEIGHT:
                this.style.setLastHeight(var2.getDoubleValue());
                break;
            case GROUPCODE_OBLIQUE_ANGLE:
                this.style.setObliqueAngle(var2.getDoubleValue());
                break;
            case GROUPCODE_FLAGS:
                this.style.setFlags(var2.getIntegerValue());
                break;
            case GROUPCODE_TEXT_GENERATION_FLAG:
                this.style.setTextGenerationFlag(var2.getIntegerValue());
                break;
            default:
                break;
        }

    }

    @Override
    public void startParsing() {
        this.style = new DXFStyle();
    }
}
